<template>
  <div class="app-main-container" style="padding-top: 10px;">
    <el-tabs v-model="active" @tab-click="handleClick">
      <el-tab-pane v-for="(tab, i) in tabList" :key="tab.id" :label="tab.manufacturer" :name="i.toString()">
        <el-form ref="ruleform" :model="form" label-suffix="：" :rules="rules" label-width="140px">
          <el-form-item label="appID" prop="appId">
            <el-input v-model="form.appId" placeholder="请输入appId" class="w400" />
          </el-form-item>
          <el-form-item label="appSecret" prop="appSecret">
            <el-input v-model="form.appSecret" placeholder="请输入appSecret" class="w400" />
          </el-form-item>
          <el-form-item label="cityNo" prop="cityNo">
            <el-input v-model="form.cityNo" placeholder="请输入cityNo" class="w400" />
          </el-form-item>
          <el-form-item label="siteId" prop="siteId">
            <el-input v-model="form.siteId" placeholder="请输入siteId" class="w400" />
            <span class="tip-style">检验站点ID</span>
          </el-form-item>
          <el-form-item label="checkUsridCard" prop="checkUsrIdCard">
            <el-input v-model="form.checkUsrIdCard" placeholder="请输入checkUsrIdCard" class="w400" />
            <span class="tip-style">检验点检查人员身份证号码或检验点设备编码</span>
          </el-form-item>
          <el-form-item label="checkUsridName" prop="checkUsrName">
            <el-input v-model="form.checkUsrName" placeholder="请输入checkUsrName" class="w400" />
            <span class="tip-style">检验点检查人员姓名或检验点设备名称</span>
          </el-form-item>
          <el-form-item>
            <el-button
              v-preventReClick
              :loading="subLoading"
              type="primary"
              @click="onSubmit('ruleform')"
            >提交</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane></el-tabs>
  </div>
</template>

<script>
import { manufacturerList, accountConfigs, accountConfigsInfo } from '@/api'
export default {
  name: 'EpidemicSite',
  data() {
    return {
      subLoading: false,
      venueId: sessionStorage.getItem('venueId'),
      tabList: [],
      active: '0',
      rules: {
        appId: [
          { required: true, message: '请输入appId', trigger: 'blur' }
        ],
        cityNo: [
          { required: true, message: '请输入cityNo', trigger: 'blur' }
        ],
        siteId: [
          { required: true, message: '请输入siteId', trigger: 'blur' }
        ],
        appSecret: [
          { required: true, message: '请输入appSecret', trigger: 'blur' }
        ],
        checkUsrIdCard: [
          { required: true, message: '请输入检验点检查人员身份证号码或检验点设备编码', trigger: 'blur' }
        ],
        checkUsrName: [
          { required: true, message: '请输入检验点检查人员姓名或检验点设备名称', trigger: 'blur' }
        ]
      },
      form: {}
    }
  },
  mounted() {
    this.tomanufacturerList()
  },
  methods: {
    onSubmit(formName) {
      const that = this
      const venueId = sessionStorage.getItem('venueId')
      this.$refs[formName][this.active].validate((valid) => {
        if (valid) {
          this.subLoading = true
          accountConfigs({
            param: {
              manufacturerId: that.tabList[this.active].id, venueId, accountParm: that.form
            }
          }).then(res => {
            this.subLoading = false
            if (res.errorCode === '000000') {
              that.$message.success('提交成功')
            }
          }).catch(err => {
            this.subLoading = false
            console.log(err)
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    tomanufacturerList() {
      manufacturerList({ param: { type: '6' }}, sessionStorage.getItem('venueId')).then(res => {
        this.tabList = res.recordList
        this.accountConfigsInfo()
      }).catch(err => {
        console.log(err)
      })
    },
    accountConfigsInfo() {
      const venueId = sessionStorage.getItem('venueId')
      accountConfigsInfo({ param: { manufacturerId: this.tabList[this.active].id, venueId }}, venueId).then(res => {
        this.form = res.record.accountParm || {}
      }).catch(err => {
        console.log(err)
      })
    },
    handleClick(e) {
      this.accountConfigsInfo()
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/styles/variables.scss";
.tip {
  font-size: 12px;
  color: #666;
  line-height: 20px;
  height: 20px;
}
</style>
